<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Chat Room By nodejs-websocket</title>
</head>
<body>
<h1 id="title">Chat Room.</h1>
<input type="text" id="text"/>
<button type="button" id="send">Send</button>
<p id="content"></p>
</body>
</html>
<script type="text/javascript">
    var content = document.getElementById("content");
    var text = document.getElementById('text');

    var ws = new WebSocket("ws://localhost:8001");
    ws.onopen = function () {
        console.log("web socket is opened.");
        document.getElementById('send').onclick = function () {
            console.log('send', text.value);
            ws.send(text.value);
        };
    };
    ws.onclose = function () {
        console.log("web socket is closed.");
    };
    ws.onmessage = function (e) {
        console.log('onmessage', e);
        content.innerHTML += e.data + '<br/>';
    };

</script>